package com.li.controller;


import com.li.model.UserModel;
import com.li.pojo.DataDto;
import com.li.service.UserService;
import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LRC
 * @since 2021-02-22
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("getUserList")
    public List<UserModel> getUserList() {
        return userService.getUserList();
    }

    @RequestMapping("getUserList2")
    public List<UserModel> getUserList2() {
        return userService.getUserList2();
    }

    @RequestMapping("add")
    public void add() {
        userService.addMore();
    }

    /**
     * 泛型映射测试
     *
     * @return
     */
    @RequestMapping("getUserList3")
    public List<DataDto> getUserList3() {
        List<DataDto> dataDtos = userService.getUserList3();
        dataDtos.forEach(s -> System.out.println(s));
        return dataDtos;
    }

    /**
     * cusor测试
     */
    @RequestMapping("getUserList4")
    @Transactional
    public void getUserList4() {
        Cursor<UserModel> cursor = userService.getUserList4();
        Cursor<UserModel> cursor1 = userService.getUserList4();
        cursor.forEach(s -> System.out.println(s));
        cursor1.forEach(s -> System.out.println(s));
        Cursor<UserModel> cursor2 = userService.getUserList4();
        cursor2.forEach(s -> System.out.println(s));

    }
}
